package com.server.llh.llhserverwork.activity.server;

import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;

import com.family.llh.lelaohuitoastview.dialog.toast.T;
import com.google.gson.Gson;
import com.lelaohui.net.BaseLeLaohuiAcitivity;
import com.lelaohui.net.listener.NetDataListener;
import com.lelaohui.net.netmanager.INetRequestManager;
import com.lelaohui.net.netmanager.NetRequestManager;
import com.lelaohui.net.request.LRequest;
import com.lelaohui.net.utils.UrlsTools;

import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.activity.base.LlhBaseNFCActivity;
import com.server.llh.llhserverwork.activity.my.LlhAddAddressActivity;
import com.server.llh.llhserverwork.adapter.LlhAddressItemAdapter;
import com.server.llh.llhserverwork.adapter.MyAccountAdapter;
import com.server.llh.llhserverwork.adapter.SerOrderHolder;
import com.server.llh.llhserverwork.adapter.UserInfoAdapter;
import com.server.llh.llhserverwork.adapter.base.ListViewDataAdapter;
import com.server.llh.llhserverwork.bean.Account;
import com.server.llh.llhserverwork.bean.AccountConstant;
import com.server.llh.llhserverwork.bean.AddressManagerBean;
import com.server.llh.llhserverwork.bean.Constants;
import com.server.llh.llhserverwork.bean.MyAddress;
import com.server.llh.llhserverwork.bean.PayList;
import com.server.llh.llhserverwork.bean.UserDataInfoBean;
import com.server.llh.llhserverwork.bean.UserInfoBena;
import com.server.llh.llhserverwork.port.ClearViewDataInterface;
import com.server.llh.llhserverwork.receiver.GetCardBroadCast;
import com.server.llh.llhserverwork.utils.Constant;
import com.server.llh.llhserverwork.utils.ListViewHeightUtil;
import com.server.llh.llhserverwork.utils.ServerPort;
import com.server.llh.llhserverwork.utils.ServerStatementData;
import com.server.llh.llhserverwork.utils.SharedPreferenceUtil;
import com.server.llh.llhserverwork.utils.ToastTool;
import com.server.llh.llhserverwork.view.AddListView;
import com.server.llh.llhserverwork.view.AlertDialog;


import org.json.JSONException;
import org.json.JSONObject;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 服务下单页面
 */
public class LlhShopingOrderActivity extends LlhBaseNFCActivity {

    private static final String TAG = "ShopingOrder";
    @BindView(R.id.order_code)
    TextView orderCode;
    @BindView(R.id.amountPayable)
    TextView amountPayable;
    @BindView(R.id.payStatus)
    TextView payStatus;
    @BindView(R.id.left_btn)
    ImageButton leftBtn;
    @BindView(R.id.titlebar_text)
    TextView titlebarText;
    @BindView(R.id.right_btn)
    Button rightBtn;
    @BindView(R.id.addAddress)
    LinearLayout addAddressLayout;
    @BindView(R.id.addressTxt)
    TextView addressTxt;
    @BindView(R.id.userNameTxt)
    TextView userNameTxt;
    @BindView(R.id.userPhoneTxt)
    TextView userPhoneTxt;
    @BindView(R.id.image_break)
    ImageView imageBreak;
    @BindView(R.id.address_content)
    RelativeLayout addressContent;
    @BindView(R.id.show_address_all)
    LinearLayout showAddressAll;
    @BindView(R.id.address_lv)
    AddListView addressLv;
    @BindView(R.id.layout_show)
    ImageView layoutShow;
    @BindView(R.id.view_pay)
    RelativeLayout viewPay;
    @BindView(R.id.radio0)
    ImageView radio0;
    @BindView(R.id.relative1)
    RelativeLayout relative1;
    @BindView(R.id.radio1)
    ImageView radio1;
    @BindView(R.id.relative2)
    RelativeLayout relative2;
    @BindView(R.id.LinearLayout1)
    LinearLayout LinearLayout1;
    @BindView(R.id.order_list)
    AddListView orderList;
    @BindView(R.id.order_content)
    LinearLayout orderContent;
    @BindView(R.id.sv_order_content)
    ScrollView svOrderContent;
    @BindView(R.id.text_money)
    TextView textMoney;
    @BindView(R.id.text_money_count)
    TextView textMoneyCount;
    @BindView(R.id.btn_commint)
    Button btnCommint;
    @BindView(R.id.show_address)
    RelativeLayout showAddress;
    LlhAddressItemAdapter llhAddressItemAdapter = null;
    @BindView(R.id.my_user_name)
    TextView myUserName;
    @BindView(R.id.user_old_man_sp)
    TextView userOldManSp;
    @BindView(R.id.pay_list)
    Spinner pay_list;
    @BindView(R.id.view_line)
    LinearLayout viewLine;
    @BindView(R.id.add_address)
    LinearLayout addAddress;
    @BindView(R.id.address)
    LinearLayout address;
    @BindView(R.id.zhifu_Style)
    TextView zhifuStyle;
    @BindView(R.id.zhifu_card)
    TextView zhifuCard;

    private List<MyAddress> objects = new ArrayList<MyAddress>();
    ServerStatementData serverStatementData;
    private String mUserId1, mUserId, accId, mOrgId, orderId, mOrgName, mOrgType, mTelePhone, mUserName1, mUserName, mToken, mPhone, amountPayableD;
    ServerStatementData.SerOrderInfoDetailBeanListBean serOrderInfoDetail;
    List<ServerStatementData.SerOrderInfoDetailBeanListBean> listBeen = new ArrayList<>();
    double myBanlance;
    GetCardBroadCast getCardBroadCast = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        IntentFilter filter = new IntentFilter();
        filter.addAction(Constant.READ_CARDACTION);
        getCardBroadCast = new GetCardBroadCast();
        getCardBroadCast.setmHandler(handler);
        getLbm().registerReceiver(getCardBroadCast, filter);
        mUserId1 = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.USER_ID, getApplicationContext());
        mPhone = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.TELE_PHONE, getApplicationContext());
        mOrgId = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.CHAIN_ID, getApplicationContext());

        mOrgName = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.CHAIN_NAME, getApplicationContext());
//        mOrgType = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.ORG_TYPE, getApplicationContext());
        mOrgType = "3";
        mUserName = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.USER_NAMW, getApplicationContext());
        mToken = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.TOKEN_STR, getApplicationContext());
        addressLv.setVisibility(View.GONE);
        serverStatementData = LlhServerMenuTwoActivity.serverStatementData;
        btnCommint.setText("购买服务");
        if (serverStatementData != null) {
            orderCode.setVisibility(View.GONE);
//            orderCode.setText("订单号:" + serverStatementData.getSerOrderInfo().getOrderCode());
            orderCode.setText("");
            amountPayable.setText("总价:￥" + serverStatementData.getSerOrderInfo().getAmountPayable() + "元");
            textMoney.setText("总价:￥" + serverStatementData.getSerOrderInfo().getAmountPayable() + "元");
            if (serverStatementData.getSerOrderInfo().getPayStatus() == 0) {
                payStatus.setText("未支付");
            }
        }
        view = LayoutInflater.from(LlhShopingOrderActivity.this).inflate(R.layout.llh_buttom_view, null);
        add_Address = (TextView) view.findViewById(R.id.add_address2);
        addressLv.addFooterView(view);
        listBeen = serverStatementData.getSerOrderInfoDetailBeanList();
        ListViewDataAdapter<ServerStatementData.SerOrderInfoDetailBeanListBean> adapter = new ListViewDataAdapter<ServerStatementData.SerOrderInfoDetailBeanListBean>(null);
        adapter.update(listBeen);
        adapter.setViewHolderClass(null, SerOrderHolder.class, this);
        orderList.setAdapter(adapter);
        ListViewHeightUtil.setListViewHeightBasedOnChildren(orderList);

        pay_list.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                payTypeInt = accountList.get(position).getAcctype();
                Log.d(TAG, "payTypeInt===" + payTypeInt);
                accId = accountList.get(position).getAccid();
                myBanlance = accountList.get(position).getBalance();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });


    }

    View view;
    private TextView add_Address;
    private int payTypeInt;

    private void setAddressData(List<AddressManagerBean.DataBean> dataBeanList) {
        objects = new ArrayList<MyAddress>();
        for (int i = 0; i < dataBeanList.size(); i++) {
            MyAddress myAddress = new MyAddress();
            myAddress.setUserName(dataBeanList.get(i).getContactName());
            myAddress.setAddressPhone(dataBeanList.get(i).getContactPhone());
            myAddress.setAddress(dataBeanList.get(i).getAddressDetail());
            myAddress.setAddressId(dataBeanList.get(i).getAddressId() + "");
            myAddress.setAddressAll(dataBeanList.get(i).getAddressAll());
            objects.add(myAddress);
        }
        if (llhAddressItemAdapter == null) {
            llhAddressItemAdapter = new LlhAddressItemAdapter(getApplicationContext(), objects);
            addressLv.setAdapter(llhAddressItemAdapter);
            addressLv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    addressLv.setSelected(true);
                    addressLv.setSelection(0);
                    addressLv.setItemChecked(0, true);
                    addressLv.performItemClick(addressLv.getChildAt(0), 0, 0);
                    addressLv.setVisibility(View.GONE);
                }
            }, 500);
        } else {
            llhAddressItemAdapter.setObjects(objects);
            llhAddressItemAdapter.notifyDataSetChanged();
        }
        addressLv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (ListView.CHOICE_MODE_SINGLE == addressLv.getChoiceMode()) {
                    setShowAddress(position);
                    setShowAddress();
                }
            }
        });
        add_Address.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (mUserId != null && !"".equals(mUserId)) {
                    Intent intent = new Intent(getApplicationContext(), LlhAddAddressActivity.class);
                    intent.putExtra("intentType", "1");
                    intent.putExtra("code", "0");
                    intent.putExtra("userId", mUserId);
                    startActivity(intent);
                } else {
                    T.showAnimToast(getApplicationContext(), "请刷卡，获取老人信息！");
                }
            }
        });
    }

    private boolean commint = false;

    @OnClick({R.id.addAddress, R.id.image_break, R.id.left_btn, R.id.right_btn, R.id.address_content, R.id.show_address_all, R.id.layout_show, R.id.view_pay, R.id.radio0, R.id.relative1, R.id.relative2, R.id.LinearLayout1, R.id.order_content, R.id.btn_commint, R.id.show_address})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.left_btn:
                onBackPressed();
                break;
            case R.id.address_content:
                break;
            case R.id.show_address_all:
                break;
            case R.id.layout_show:
                break;
            case R.id.view_pay:
                break;
            case R.id.radio0:
                break;

            case R.id.LinearLayout1:
                break;
            case R.id.order_content:
                break;
            case R.id.btn_commint:
                if (serverStatementData == null) {
                    T.showAnimToast(getApplicationContext(), "数据为空");
                    return;
                }
                if (!commint) {
                    uploadSerOrder(serverStatementData);
                } else {
//                    if (serverStatementData.getSerOrderInfo() != null ) {
//                        if (myBanlance >= serverStatementData.getSerOrderInfo().getAmountPayable()) {
//                            reqOrderPatment(accId, payTypeInt, orderId, amountPayableD, mOrgId);
//                        } else {
//                            T.showAnimToast(getApplicationContext(), "余额不足，请选择其他账户，进行支付！");
//                        }
//                    }
                }

                break;
            case R.id.show_address:
                break;
            case R.id.image_break:
                setShowAddress();
                break;
        }
    }

    private void setShowAddress() {
        if (objects != null && addressLv.getVisibility() == View.GONE) {
            imageBreak.setVisibility(View.VISIBLE);
            addressLv.setVisibility(View.VISIBLE);
        } else if (addressLv.getVisibility() == View.VISIBLE) {
            addressLv.setVisibility(View.GONE);
        }
    }


    String cardId;
    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (msg.what == -1000) {
                cardId = String.valueOf(msg.obj);
                Log.d(TAG, "cardId==" + cardId);
                getUserInfo(String.valueOf(cardId));
            }
        }
    };

    AddressManagerBean addressManagerBean = null;
    List<AddressManagerBean.DataBean> dataBeanList = new ArrayList<AddressManagerBean.DataBean>();
    /**
     * 获取地址列表
     *
     * @param userId
     */
    private String addressName, addressPhone, addressAll;

    private void reqMyAddressList(String code, String userId) {
        Log.d(TAG, "获取我的地址。。。。");
        LRequest lRequest = new LRequest();
        lRequest.addParam("code", code);
        lRequest.addParam("userId", userId);
        lRequest.addParam("addressType", 1);
        lRequest.addParam("token", mToken);
        lRequest.setUri(ServerPort.GET_MY_ADDRESS);
        lRequest.setIp(UrlsTools.REQ_URL);
        lRequest.setType(String.class);
        requestData(lRequest, new NetDataListener<String>() {
            @Override
            public void onError(Throwable t) {
                T.showAnimErrorToast(LlhShopingOrderActivity.this, "请求超时！");
            }

            @Override
            public void onNext(String responseBean, String code) {
                Log.d(TAG, "responseBean==" + responseBean);
                if (responseBean != null && "0".equals(code)) {
                    dataBeanList.clear();
                    addressManagerBean = new Gson().fromJson(responseBean.toString(), AddressManagerBean.class);
                    dataBeanList = addressManagerBean.getData();
                    if (dataBeanList != null && dataBeanList.size() > 0) {
                        Log.d(TAG, "dataBeanList==" + dataBeanList.size());
                        addAddress.setVisibility(View.GONE);
                        address.setVisibility(View.VISIBLE);
                        setAddressData(dataBeanList);
                        for (int i = 0; i < dataBeanList.size(); i++) {
                            if ("1".equals(dataBeanList.get(i).getAddressDefault())) {
                                setShowAddress(i);
                                return;
                            }
                        }
                    } else {
                        addAddress.setVisibility(View.VISIBLE);
                        address.setVisibility(View.GONE);
                    }
                } else {
                    addAddress.setVisibility(View.VISIBLE);
                    address.setVisibility(View.GONE);
                    T.showAnimToast(getApplicationContext(), "地址信息为空！");
                }
            }
        });
    }

    /**
     * 提交订单
     */
    private String serOrderInfoStr = null;

    private void uploadSerOrder(final ServerStatementData serverStatementData) {
        {
            if (addressAll == null) {
                T.showAnimToast(getApplicationContext(), "用户信息不全，不能下单！");
                return;
            }
            try {
                Log.d(TAG, "addressAll==" + addressAll);
                ServerStatementData.SerOrderInfo serOrderInfo = serverStatementData.getSerOrderInfo();
                String address = addressName + "(" + addressPhone + "):" + addressAll;
                serOrderInfo.setContactAddress(address);
                serOrderInfo.setCustomerId(mUserId);
                serOrderInfo.setCustomerName(mUserName1);
                serOrderInfo.setCustomerPhone(mTelePhone);
                serOrderInfo.setOrgName(mOrgName);
                serOrderInfo.setOrgId(mOrgId);
                serOrderInfo.setOrgTypeId(mOrgType);
                serOrderInfo.setOrderPersionId(mUserId1);
                Log.d(TAG, "mUserName==" + mUserName);
                serOrderInfo.setOrderPersionName(mUserName);
                serOrderInfo.setPayStatus(payTypeInt);
                serverStatementData.setSerOrderInfo(serOrderInfo);
                serOrderInfoStr = new Gson().toJson(serverStatementData);
                Log.d(TAG, "serOrderInfoStr==" + serOrderInfoStr);
                LRequest lRequest = new LRequest();
                lRequest.addParam("token", mToken);
                lRequest.addParam("orgId", mOrgId);
                Log.d(TAG, "mOrgId222==" + mOrgId);
                lRequest.addParam("serProPackBeanStr", URLEncoder.encode(serOrderInfoStr, "UTF-8"));
                lRequest.setUri(ServerPort.SERVER_ORDER_INFO);
                lRequest.setIp(UrlsTools.SERVER_REQ_URL);
                lRequest.setReqType(UrlsTools.SERVER_INFO);
                lRequest.setType(String.class);
                requestData(lRequest, new NetDataListener<String>() {
                    @Override
                    public void onError(Throwable t) {
                        T.showAnimErrorToast(getApplicationContext(), getResources().getString(R.string.toast_str));
                    }

                    @Override
                    public void onNext(String responseBean, String code) {
                        if (responseBean != null) {
                            Log.d(TAG, "responseBean==" + responseBean);
                            try {
                                if ("200".equals(code)) {
                                    JSONObject obj = new JSONObject(responseBean);
                                    amountPayableD = obj.getString("amountPayable");
                                    orderId = obj.getString("orderId");
//                                    commint = true;

//                                    T.showAnimToast(getApplicationContext(), "下单成功，请确认支付！");
                                    if (serverStatementData.getSerOrderInfo() != null) {
                                        if (myBanlance >= serverStatementData.getSerOrderInfo().getAmountPayable()) {
                                            reqOrderPatment(accId, payTypeInt, orderId, amountPayableD, mOrgId);
                                        } else {
                                            T.showAnimToast(getApplicationContext(), "余额不足，请选择其他账户，进行支付！");
                                        }
                                    }
                                } else {
                                    commint = false;
                                    T.showAnimToast(getApplicationContext(), "下单失败，请重新提交！");
                                }

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        } else {
                            T.showAnimToast(getApplicationContext(), "下单失败，请重新提交！");
                        }
                    }
                });

            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
    }

    /**
     * 设置显示地址信息
     *
     * @param i
     */
    private void setShowAddress(int i) {
        Log.d(TAG, "dataBeanList==" + dataBeanList.size());
        addressName = dataBeanList.get(i).getContactName();
        addressPhone = dataBeanList.get(i).getContactPhone();
        addressAll = dataBeanList.get(i).getAddressAll();
        addressTxt.setText("" + addressAll);
        userNameTxt.setText("" + addressName);
        userPhoneTxt.setText("" + addressPhone);
    }

    @OnClick({R.id.addAddress, R.id.add_address})
    public void onViewClicked(View view) {
        Intent intent = null;
        switch (view.getId()) {
            case R.id.addAddress:

                if (mUserId != null && !"".equals(mUserId)) {
                    intent = new Intent(getApplicationContext(), LlhAddAddressActivity.class);
                    intent.putExtra("intentType", "1");
                    intent.putExtra("code", "0");
                    intent.putExtra("userId", mUserId);

                } else {
                    T.showAnimToast(getApplicationContext(), "请刷卡，获取老人信息！");
                }
                break;
            case R.id.add_address:

                if (mUserId != null && !"".equals(mUserId)) {
                    intent = new Intent(getApplicationContext(), LlhAddAddressActivity.class);
                    intent.putExtra("intentType", "1");
                    intent.putExtra("code", "0");
                    intent.putExtra("userId", mUserId);

                } else {
                    T.showAnimToast(getApplicationContext(), "请刷卡，获取老人信息！");
                }

                break;
        }
        if (intent != null) {
            startActivity(intent);
        }
    }

    Account account = null;
    MyAccountAdapter accountAdapters = null;
    List<Account.DataBean> accountList = new ArrayList<Account.DataBean>();


    public void accoutByRelated(String userId) {
        LRequest lRequest = new LRequest();
        lRequest.addParam("token", mToken);
        lRequest.addParam("userId", userId);
        lRequest.addParam("accTypes", "1,6,7,10");
        lRequest.setUri(ServerPort.ACC_BY_RELATED);
        lRequest.setUriType(UrlsTools.ACCOUNT_INFO);
        lRequest.setIp(UrlsTools.REQ_URL);
        lRequest.setType(String.class);
        requestData(lRequest, new NetDataListener<String>() {
            @Override
            public void onError(Throwable t) {
                T.showAnimErrorToast(getApplicationContext(), "请求超时！");
            }

            @Override
            public void onNext(String responseBean, String code) {
                if (responseBean != null && "0".equals(code)) {
                    Log.d(TAG, "responseBean222==" + responseBean);
                    account = new Gson().fromJson(responseBean, Account.class);
                    if (account != null) {
                        if (account.getData() != null && account.getData().size() > 0) {
                            accountList = account.getData();
                            accountAdapters = new MyAccountAdapter(getApplicationContext(), accountList);
                            pay_list.setAdapter(accountAdapters);
//                            pay_list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
//                            Handler handler = new Handler();
//                            handler.postDelayed(new Runnable() {
//                                @Override
//                                public void run() {
//
//                                    pay_list.setSelected(true);
//                                    pay_list.setSelection(0);
//                                    pay_list.setItemChecked(0, true);
//                                    pay_list.performItemClick(pay_list.getChildAt(0), 0, 0);
//                                }
//                            }, 500);
                        }
                    }
                } else {
                    T.showAnimToast(getApplicationContext(), "账户信息为空！");
                }
            }
        });
    }

    /**
     * 下单支付
     *
     * @param orderId
     * @param amount
     */
    private void reqOrderPatment(String accId, int getAcctype, String orderId, String amount, String mOrgId) {
        try {
            PayList payList = new PayList();
            if (getAcctype == 1) {
                payList.add(accId, AccountConstant.PayType.CASH_ACCOUNT, Double.valueOf(amount), mOrgId);
            } else if (getAcctype == 6 || getAcctype == 7) {
                payList.add(accId, AccountConstant.PayType.ACTIVE_CARD, Double.valueOf(amount), mOrgId);
            } else if (getAcctype == 10) {
                payList.add(accId, AccountConstant.PayType.COUPON, Double.valueOf(amount), mOrgId);
            }
            payList.setOrderid(orderId);
            String payStr = new Gson().toJson(payList);
            Log.d(TAG, "payStr===" + payStr);
            LRequest lRequest = new LRequest();
            lRequest.addParam("userId", mUserId);
            lRequest.addParam("type", 21);
            lRequest.addParam("orderId", orderId);
            lRequest.addParam("payType", payTypeInt);
            lRequest.addParam("amount", amount);
            lRequest.addParam("token", mToken);
            lRequest.addParam("realId", mUserId1);
            lRequest.addParam("token", mToken);
            lRequest.addParam("supplierType", "4");
            lRequest.addParam("supplierName", SharedPreferenceUtil.getUserInfo(Constants.UserInfo.ORG_NAME, getApplicationContext()));
            lRequest.addParam("supplierId", SharedPreferenceUtil.getUserInfo(Constants.UserInfo.ORG_ID, getApplicationContext()));
            lRequest.addParam("payList", URLEncoder.encode(payStr, "utf-8"));
            lRequest.addParam("memo", "");
            Log.d(TAG, "mUserName1===" + mUserName1);
            lRequest.addParam("realName", URLEncoder.encode(mUserName1, "utf-8"));
            lRequest.setUri(ServerPort.SERVER_ORDER_PAY);
            lRequest.setReqType(UrlsTools.SERVER_INFO);
            lRequest.setIp(UrlsTools.SERVER_REQ_URL);
            lRequest.setType(String.class);
            requestData(lRequest, new NetDataListener<String>() {
                @Override
                public void onError(Throwable t) {
                    T.showAnimErrorToast(getApplicationContext(), getResources().getString(R.string.toast_str));
                }
                @Override
                public void onNext(String responseBean, String code) {
                    Log.d(TAG, "responseBean33333==" + responseBean.toString());
                    if ("200".equals(code)) {
                        showInfo(0);
                    } else {
                        showInfo(1);
                    }
                }
            });
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    UserDataInfoBean userDataInfoBean = null;

    public void getUserInfo(String icNumber) {
        LRequest lRequest = new LRequest();
        lRequest.addParam("token", mToken);
        lRequest.addParam("icNumber", icNumber);
        lRequest.setUri(ServerPort.GET_CARD_INFO);
        lRequest.setUriType("");
        lRequest.setIp(UrlsTools.REQ_URL);
        lRequest.setType(String.class);
        requestData(lRequest, new NetDataListener<String>() {
            @Override
            public void onError(Throwable t) {
                T.showAnimErrorToast(getApplicationContext(), "请求超时！");
            }

            @Override
            public void onNext(String responseBean, String code) {
                if (responseBean != null && "0".equals(code)) {
                    userDataInfoBean = new Gson().fromJson(responseBean, UserDataInfoBean.class);
                    userOldManSp.setText(userDataInfoBean.getData().getUserName());
                    myUserName.setText("请选择");
                    mOrgId = userDataInfoBean.getData().getUserOrgId();
                    mTelePhone = userDataInfoBean.getData().getContactPhone();
                    mUserId = userDataInfoBean.getData().getUserId();
                    if (userDataInfoBean.getData().getUserNickName() != null) {
                        mUserName1 = userDataInfoBean.getData().getUserName() + "(" + userDataInfoBean.getData().getUserNickName() + ")";
                    } else {
                        mUserName1 = userDataInfoBean.getData().getUserName();
                    }
                    accoutByRelated(userDataInfoBean.getData().getUserId());
                    reqMyAddressList("3", userDataInfoBean.getData().getUserId());
                } else {
                    ToastTool.showText(getApplicationContext(), "没有找到该卡所对应的用户信息！");
                }
            }
        });
    }

    @Override
    protected void onResume() {
        if (userDataInfoBean != null) {
            reqMyAddressList("3", userDataInfoBean.getData().getUserId());
        }
        super.onResume();
    }

    private void showInfo(final int payStatus) {
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        if (payStatus == 0) {
            builder.setTitle("订单支付成功！");
            builder.setMessage("\n" + "订单支付成功，祝你生活愉快！" + "\n");
        } else {
            builder.setTitle("订单支付失败！");
            builder.setMessage("\n" + "余额不足支付失败！" + "\n");
        }
        builder.setNegativeButton("确认退出", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
//                if (payStatus == 0) {
                clearViewDataInterfaces.clearShopData("1");
//                    Intent intent = new Intent(getApplicationContext(), LlhServerOrderBaseFragment.class);
//                    startActivity(intent);
                finish();
//                } else {
//                    clearViewDataInterfaces.clearShopData("1");
////                    Intent intent = new Intent(getApplicationContext(), LlhServerOrderBaseFragment.class);
////                    intent.putExtra("userId", mUserId);
////                    startActivity(intent);
//                    finish();
//                }
                dialog.cancel();
            }
        });
        builder.setPositiveButton("继续订购", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                clearViewDataInterfaces.clearShopData("0");
                finish();
                dialog.cancel();
            }
        });
        builder.show();
    }

    protected int getlayout() {
        return R.layout.llh_shoping_order;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void doBasess() {

    }

    public void showProgress() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    showProgress(LlhShopingOrderActivity.this);
                } catch (Exception e) {
                }
            }
        });
    }

    public void hideProgress() {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                    closeProgress();
                } catch (Exception e) {
                }
            }
        });
    }

    protected INetRequestManager getRequestManager() {
        return NetRequestManager.getInstance();
    }

    static ClearViewDataInterface clearViewDataInterfaces = null;

    public static void registCallBack(ClearViewDataInterface clearViewDataInterface) {
        clearViewDataInterfaces = clearViewDataInterface;
    }

    @Override
    protected void onDestroy() {
        try {
            if (getCardBroadCast != null) {
                getLbm().unregisterReceiver(getCardBroadCast);
            }
        } catch (Exception e) {
            Log.e(TAG, e.getMessage());
        }
        super.onDestroy();
    }
}